#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    ListNode* swapPairs(ListNode* head)
    {
        ListNode* NewHead, * cur;
        NewHead = cur = new ListNode(-1);
        cur->next = head;
        while (cur->next != nullptr && cur->next->next != nullptr)
        {
            ListNode* Node1 = cur->next;
            ListNode* Node2 = cur->next->next;
            Node1->next = Node2->next;
            Node2->next = Node1;
            cur->next = Node2;
            cur = Node1;
        }
        cur = NewHead;
        NewHead = NewHead->next;
        delete cur;
        return NewHead;
    }
};

class Solution {
public:
    ListNode* swapPairs(ListNode* head)
    {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode* NewHead = head->next;
        head->next = swapPairs(NewHead->next);
        NewHead->next = head;
        return NewHead;
    }
};

